import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/session',
    method: 'post',
    data
  })
}

export function regist(data) {
  return request({
    url: '/regist',
    method: 'post',
    data
  })
}

export function addUser(data) {
  return request({
    url: '/users',
    method: 'post',
    data
  })
}

export function getInfo(payload) {
  return request({
    url: payload.name ? '/users/' + payload.name : '/users',
    method: 'get',
    params: {
      page: payload.page,
      pageSize: payload.pageSize
    },
    headers: { 'x-token': payload.token }
  })
}

export function delUser(payload) {
  return request({
    url: '/users/' + payload.username,
    method: 'delete',
    data: payload.option === 0 ? {} : { password: payload.password },
    params: {
      option: payload.option
    }
    // headers: { 'x-token': payload.token }
  })
}

export function updateUser(payload) {
  return request({
    url: '/users',
    method: 'put',
    data: payload
    // headers: { 'x-token': payload.token }
  })
}

// export function logout() {
//   return request({
//     url: '/vue-admin-template/user/logout',
//     method: 'post'
//   })
// }
